package com.wyz.saas.app.set

import com.atom.annotation.Impl
import com.atom.api.ApiContext
import com.atom.api.ApiContextAware
import com.wyz.saas.api.set.AppSetter
import java.util.*

@Impl(api = AppSetter::class)
class AppSetterImpl : AppSetter, ApiContextAware {

    private lateinit var mApi: ApiContext

    override fun setApiContextAware(context: ApiContext) {
        this.mApi = context
    }

    override fun get(label: String): String? {
        return getEntity(label)?.getValue()
    }

    override fun set(
        label: String,
        value: Any?,
        face: String?,
        name: String?,
        type: String?,
        comments: String?
    ): Boolean {
        var appset: AppSet? = null
        val b = getEntity(label)?.let {
            appset = it
            it.setValue(value?.toString())
            it.setFace(face)
            it.setName(name)
            it.setType(type)
            it.setComments(comments)
//            it.update() TODO 保存
        } ?: let {
            AppSet().apply {
                this.setId(UUID.randomUUID().toString())
                this.setLabel(label)
                this.setValue(value?.toString())
                this.setFace(face)
                this.setName(name)
                this.setType(type)
                this.setComments(comments)
            }.also {
                appset = it
            }//.save() TODO 保存

        }
        return false
    }


    private fun getEntity(label: String): AppSet? {
        return AppSet()
    }
}